package com.ebelter.ty.ui.activity;


import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.ty.AppConfig;
import com.ebelter.ty.R;
import com.ebelter.ty.model.http.bean.HostoryListData;
import com.ebelter.ty.utils.ScaleBaseUtils;

import butterknife.BindView;
import butterknife.OnClick;

import static com.ebelter.ty.adapters.HostoryListAdapter.NO_RESULT;

public class HistoryItemDetailActivity extends BaseActivity {

    private static final String TAG = "HistoryListActivity";

    ImageView back_iv;
    public static final String ITEMDATD = "d";


    TextView hostory_d_time_tv;



    TextView hostory_weight_tv;


    TextView hostory_bodyfatpercentage_tv;


    TextView hostory_bmi_tv;


    TextView hostory_bmr_tv;


    TextView hostory_musclemass_tv;


    TextView hostory_bonemincontent_tv;


    TextView hostory_protein_tv;


    TextView hostory_bodywaterpercentage_tv;


    TextView hostory_skeletal_tv;


    TextView hostory_vfl_tv;

    @Override
    protected void initView() {
        back_iv=findViewById(R.id.modify_back_bt);
        back_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        hostory_d_time_tv=findViewById(R.id.hostory_d_time_tv);
        hostory_weight_tv=findViewById(R.id.hostory_weight_tv);
        hostory_bodyfatpercentage_tv=findViewById(R.id.hostory_bodyfatpercentage_tv);
        hostory_bmi_tv=findViewById(R.id.hostory_bmi_tv);
        hostory_bmr_tv=findViewById(R.id.hostory_bmr_tv);
        hostory_musclemass_tv=findViewById(R.id.hostory_musclemass_tv);
        hostory_bonemincontent_tv=findViewById(R.id.hostory_bonemincontent_tv);
        hostory_protein_tv=findViewById(R.id.hostory_protein_tv);
        hostory_bodywaterpercentage_tv=findViewById(R.id.hostory_bodywaterpercentage_tv);
        hostory_skeletal_tv=findViewById(R.id.hostory_skeletal_tv);
        hostory_vfl_tv=findViewById(R.id.hostory_vfl_tv);


    }

    private String unitKg = StringUtils.getResStr(R.string.kg);
    private String unitLb = StringUtils.getResStr(R.string.lb);

    private void setDatas(HostoryListData.ResultDataBean.DataBean itemData) {
        hostory_d_time_tv.setText(ScaleBaseUtils.timeFatmat(itemData.getTestDate(),3));//时间
        float w= NumUtils.numBaoLiuWei1(ScaleBaseUtils.adapterDataFloat((float) itemData.getWeight()));
        hostory_weight_tv.setText(numFatmat(w, AppConfig.getInstance().isKgModel()?unitKg:unitLb));//体重

        float fat=NumUtils.numBaoLiuWei1((float) itemData.getAdiposeRate());
        hostory_bodyfatpercentage_tv.setText(numFatmat2(fat,"%"));//内脂


        float bmi=NumUtils.numBaoLiuWei1((float) itemData.getBmi());
        hostory_bmi_tv.setText(numFatmat(bmi,""));

        int bmr=itemData.getBmr();


        StringUtils.setTextUseSpannable(hostory_bmr_tv,bmr,StringUtils.getResStr(R.string.kcal_d),28);

        float vfl=NumUtils.numBaoLiuWei1((float) itemData.getVisceralFat());
        hostory_vfl_tv.setText(numFatmat(vfl,""));

        float m= NumUtils.numBaoLiuWei1(ScaleBaseUtils.adapterDataFloat((float) itemData.getMuscleQuantity()));
        hostory_musclemass_tv.setText(numFatmat(m,AppConfig.getInstance().isKgModel()?unitKg:unitLb));

        float b= NumUtils.numBaoLiuWei1(ScaleBaseUtils.adapterDataFloat((float) itemData.getBoneMass()));
        hostory_bonemincontent_tv.setText(numFatmat(b,AppConfig.getInstance().isKgModel()?unitKg:unitLb));

        float pr=NumUtils.numBaoLiuWei1((float) itemData.getProtein());
        hostory_protein_tv.setText(numFatmat2(pr,"%"));

        float moisture=NumUtils.numBaoLiuWei1((float) itemData.getMoisture());
        hostory_bodywaterpercentage_tv.setText(numFatmat2(moisture,"%"));//水分

        float g= NumUtils.numBaoLiuWei1(ScaleBaseUtils.adapterDataFloat((float) itemData.getBoneMineralContent()));
        hostory_skeletal_tv.setText(numFatmat(g,AppConfig.getInstance().isKgModel()?unitKg:unitLb));//gu
    }

    private String numFatmat(float value,String unit){
        if (value<=0){
            return NO_RESULT;
        }else {
            if (TextUtils.equals(unit,unitLb)){
                return ScaleBaseUtils.unitDisplay2(value+"",unitLb);
            }
            return value+unit;
        }
    }


    private String numFatmat2(float value,String unit){
        if (value<=0){
            return NO_RESULT;
        }else {
            return ScaleBaseUtils.unitDisplay2(value+"",unit);
        }
    }
    private String numFatmat2(int value,String unit){
        if (value<=0){
            return NO_RESULT;
        }else {
            return ScaleBaseUtils.unitDisplay2(value+"",unit);
        }
    }

    @Override
    protected int loadLayoutById() {
        return R.layout.hostoryitemdetail_ly;
    }



    HostoryListData.ResultDataBean.DataBean itemData;
    @Override
    protected void initData() {
        itemData = (HostoryListData.ResultDataBean.DataBean) getIntent().getSerializableExtra(ITEMDATD);
        if (itemData==null){
            finish();
            return;
        }
        setDatas(itemData);
    }









}
